% \usetheme{Madrid}
% \usecolortheme{beaver}

% Layout scheme for outer elements: split header and footer
\useoutertheme{split}

% Color scheme for outer elements: use background colors
\usecolortheme{whale}

% Layout scheme for inner elements: rounded elements
\useinnertheme{rounded}

% Color scheme for inner elements: use foreground colors
\usecolortheme{orchid}

%%%
%%% Tweak definitions of inner theme to match personal preferences (MODIFY THESE)
%%%

% Itemize items: default (triangle), circle, square, ball
\setbeamertemplate{itemize items}[circle]

% Enumerate items: default, circle, square, ball
\setbeamertemplate{enumerate items}[circle]

% Outline: default, sections numbered, subsections numbered, circle, square, ball, ball unnumbered
\setbeamertemplate{sections/subsections in toc}[default]

% General blocks:
\setbeamertemplate{blocks}[rounded]

% Title page:
\setbeamertemplate{title page}[default][colsep=-4bp,rounded=true]

% Part page:
\setbeamertemplate{part page}[default][colsep=-4bp,rounded=true]

% % font in math
% \usefonttheme[onlymath]{serif}

% Colors
\usecolortheme[RGB={182,11,45}]{structure}
%\usecolortheme[RGB={0,98,109}]{structure}

\setbeamercolor{frametitle}{parent=subsection in head/foot}
\setbeamercolor{frametitle right}{parent=section in head/foot}


\pgfdeclarehorizontalshading[frametitle.bg,frametitle right.bg]{beamer@frametitleshade}{\paperheight}{%
  color(0pt)=(frametitle.bg);
  color(\paperwidth)=(frametitle right.bg)}

\AtBeginDocument{
  \pgfdeclareverticalshading{beamer@topshade}{\paperwidth}{%
    color(0pt)=(bg);
    color(4pt)=(black!50!bg)}
}

% Background
\pgfdeclareimage[width=\paperwidth,height=\paperheight]{bg}{background}
\setbeamertemplate{background}{\pgfuseimage{bg}}

% Footline: AUTHOR | TITLE | DATE FRAMENUMBER

\defbeamertemplate*{footline}{ecnu theme}{%
  \leavevmode%
  \hbox{%
  \begin{beamercolorbox}[wd=.25\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
    \usebeamerfont{author in head/foot}\insertshortauthor
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.25\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
    \usebeamerfont{author in head/foot}\insertshortinstitute
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.435\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
    \usebeamerfont{title in head/foot}\insertshorttitle
  \end{beamercolorbox}%
   \begin{beamercolorbox}[wd=0.065\paperwidth,ht=2.25ex,dp=1ex,right]{title in head/foot}%
    \insertframenumber{} / \inserttotalframenumber\hspace*{2ex}
  \end{beamercolorbox}}%
  \vskip0pt%
}

\defbeamertemplate*{headline}{ecnu theme}{%
  \leavevmode%
  \@tempdimb=6.4375ex%
    %\multiply\@tempdimb by\beamer@sectionmax%
    % \pgfdeclareimage[height=.95\@tempdimb]{logo}{logo.png}%
    \pgfdeclareimage[height=1.\@tempdimb]{title_logo}{logo.png}%
  \logo{\pgfuseimage{logo}}%
  \ifdim\@tempdimb>0pt%
    \advance\@tempdimb by 1.125ex%
    \begin{beamercolorbox}[wd=.8\paperwidth,ht=\@tempdimb]{section in head/foot}%
      \vbox to\@tempdimb{\vfil\insertsectionnavigationhorizontal{.5\textwidth}{\hskip0pt plus1filll}{}\vfil}%
    \end{beamercolorbox}%
    %% \begin{beamercolorbox}[wd=.4\paperwidth,ht=\@tempdimb,center]{subsection in head/foot}%
    %%   \vbox to\@tempdimb{\vfil\textbf{\footnotesize\insertshortinstitute~~}\vfil}%
    %% \end{beamercolorbox}%
    \begin{beamercolorbox}[wd=.2\paperwidth,ht=\@tempdimb,center]{subsection in head/foot}%
      \vbox to\@tempdimb{\vfil\pgfuseimage{title_logo}\vfil}%
    \end{beamercolorbox}%
    % \begin{beamercolorbox}[wd=.065\paperwidth,ht=\@tempdimb,center]{subsection in head/foot}%
    %   \vbox to\@tempdimb{\vfil\insertlogo\vfil\vfil}%
    % \end{beamercolorbox}%
  \fi%
}

\defbeamertemplate*{frametitle}{ecnu theme}{%
  \nointerlineskip%
  %\vskip-2pt%
  \hbox{\leavevmode
    \advance\beamer@leftmargin by -12bp%
    \advance\beamer@rightmargin by -12bp%
    \beamer@tempdim=\textwidth%
    \advance\beamer@tempdim by \beamer@leftmargin%
    \advance\beamer@tempdim by \beamer@rightmargin%
    \hskip-\Gm@lmargin\hbox{%
      \setbox\beamer@tempbox=\hbox{\begin{minipage}[b]{\paperwidth}%
          \vbox{}\vskip-.75ex%
          \leftskip0.3cm%
          \rightskip0.3cm plus1fil\leavevmode
          \insertframetitle%
          \ifx\insertframesubtitle\@empty%
            \strut\par%
          \else
            \par{\usebeamerfont*{framesubtitle}{\usebeamercolor[fg]{framesubtitle}\insertframesubtitle}\strut\par}%
          \fi%
          \nointerlineskip
          \vbox{}%
          \end{minipage}}%
      \beamer@tempdim=\ht\beamer@tempbox%
      \advance\beamer@tempdim by 2pt%
      \begin{pgfpicture}{0.1mm}{0pt}{1.01\paperwidth}{\beamer@tempdim}
        \usebeamercolor{frametitle right}
        \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{\beamer@tempdim}}
        \pgfusepath{clip}
        \pgftext[left,base]{\pgfuseshading{beamer@frametitleshade}}
      \end{pgfpicture}
      \hskip-\paperwidth%
      \box\beamer@tempbox%
    }%
    \hskip-\Gm@rmargin%
  }%
%  \nointerlineskip
%    \vskip-0.2pt
%    \hbox to\textwidth{\hskip-\Gm@lmargin\pgfuseshading{beamer@topshade}\hskip-\Gm@rmargin}
%    \vskip-2pt
}
